#include <iostream>
#include <string>
#include <winsock2.h>
using namespace std;
int main(){
	WORD wVerReq;
	WSADATA wsaData;
	//Using MAKEWORD macro
	wVerReq = MAKEWORD(2,2);
	//
	int wsaErr = WSAStartup(wVerReq,&wsaData);
	if(wsaErr != 0){
		cout << "Ko thay' winsock dll file" << endl;
		return 0;
	}
	//Tao. socket
	// using AF_INET family, TCP socket type and protocol of the AF_INET - IPv4
	SOCKET cli_socket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
	sockaddr_in cli_socketaddr;

	cli_socketaddr.sin_family = AF_INET;
	cli_socketaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
	cli_socketaddr.sin_port = htons(6874);
	//connect()
	connect(cli_socket,(SOCKADDR*)&cli_socketaddr,sizeof(cli_socketaddr));
	//send() and recv()
	string client_request = "Hello , I am client ^^!";
	send(cli_socket,client_request.c_str(),client_request.size(),0);
	int sizebuf = 500;
	char buf[501];
	int isok = recv(cli_socket,buf,sizebuf,0);
	if(isok != -1){
		cout << "server > " << buf << endl;
	}
	return 0;
}